﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Diagnostics;
using System.Linq;
using System.ServiceProcess;
using System.Text;
using System.Timers;

namespace RoolDesktopService
{
    partial class AutoRunService : ServiceBase
    {
        public AutoRunService()
        {
            InitializeComponent();
        }
        Timer timer;
        static readonly string filePath = @"F://RollDesktop.exe";
        protected override void OnStart(string[] args)
        {
            // TODO: 键入InstallUtil exe路径 加-u是注销
            // TODO: 在此处添加代码以启动服务。
            timer = new Timer();
            timer.Interval = 10000;
            timer.Enabled = true;
            timer.AutoReset = true;
            timer.Elapsed += new ElapsedEventHandler(timer_elapsed);
        }

        protected override void OnStop()
        {
            // TODO: 在此处添加代码以执行停止服务所需的关闭操作。
            timer.Enabled = false;
        }

        private void timer_elapsed(object sender, ElapsedEventArgs args)
        {
            Process[] p = Process.GetProcessesByName("RollDesktop");
            foreach (Process item in p)
            {
                item.Kill();
            }
            Process.Start(filePath);
        }
    }
}
